<?php

namespace App\Containers\AppSection\Questionnaire\Tasks;

use App\Containers\AppSection\Questionnaire\Data\Repositories\ValueRepository;
use App\Ship\Exceptions\DeleteResourceFailedException;
use App\Ship\Parents\Tasks\Task;
use Exception;

class DeleteAllValuesByResponseIdTask extends Task
{
    protected ValueRepository $repository;

    public function __construct(ValueRepository $repository)
    {
        $this->repository = $repository;
    }

    public function run($responseId): ?int
    {
        try {
            return $this->repository->deleteWhere(['response_id' => $responseId]);
        } catch (Exception $exception) {
            throw new DeleteResourceFailedException();
        }
    }
}
